//
//  OldManAccount.swift
//  LeGou
//
//  Created by lxm on 2022/8/3.
//

import UIKit

class OldManAccount: ZMViewController, UITableViewDelegate, UITableViewDataSource {

    //MARK:--------------------属性--------------------
    let listData = ["","","","","","","",""]
    //MARK:--------------------UI控件--------------------
    @IBOutlet weak var tableView: UITableView!
    
    let header = ZMUtil.loadNibView(nibName: OldHeader.self)
    //MARK:--------------------生命周期--------------------
    override func viewDidLoad() {
        super.viewDidLoad()
        setUI()
        addConstraints()
        bindAction()
    }
    
    //MARK:--------------------UI--------------------
    func setUI() {
        title = "消费养老账户"
        tableView.delegate = self
        tableView.dataSource = self
        tableView.zm.register(nibName: "OldAccountListCell", reuserId: "OldAccountListCell")
        header.layoutIfNeeded()
        
//        header.autoresizingMask = .flexibleHeight
//        tableView.tableHeaderView = header
//        print(header.frame, "header frame")
//        header.zm.setHeight(500)
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        header.zm.setHeight(310)
        tableView.tableHeaderView = header
    }
    
    func addConstraints() {
        
    }
    
    //MARK:--------------------methods--------------------
    func bindAction() {
        
    }
    

    //MARK:--------------------delegate--------------------
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return listData.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "OldAccountListCell") as! OldAccountListCell
        return cell
    }
    
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        let allCount = self.listData.count
        let current = indexPath.row
        if allCount == 1 {
            ZMUtil.clipCircle(view: cell, Corner: [.topLeft, .topRight, .bottomLeft, .bottomRight], radius: 12)
        } else {
            if current == 0 {
                ZMUtil.clipCircle(view: cell, Corner: [.topLeft, .topRight,], radius: 12)
            } else if current == allCount - 1 {
                ZMUtil.clipCircle(view: cell, Corner: [.bottomLeft, .bottomRight], radius: 12)
            } else {
                cell.layer.mask = nil
            }
        }
    }
}
